<template>
  <div class="student-manage">
    <div class="student-content">
      <student-comp :schoolId="schoolId" :updateMsg="updateMsg"></student-comp>
    </div>
  </div>
</template>

<script>
import StudentComp from '@/components/schoolmanage/studentComp.vue';
import { mapState, mapActions, mapGetters } from 'vuex';

export default {
  name: 'StudentManage',
  components: {
    StudentComp
  },
  data() {
    return {
      updateMsg: 0
    };
  },
  computed: {
    ...mapState('school', ['schoolList', 'currentSchoolId']),
    ...mapGetters('school', ['currentSchool']),
    schoolId() {
      return this.currentSchoolId;
    }
  },
  watch: {
    currentSchoolId: {
      handler(newVal) {
        if (newVal) {
          this.updateMsg++;
        }
      },
      immediate: true
    }
  },
  methods: {
    ...mapActions('school', ['GET_SCHOOL_LIST', 'GET_SCHOOL_OPTIONS']),
    async initData() {
      try {
        console.log('StudentManage: 初始化数据开始');
        await this.GET_SCHOOL_LIST();
        
        console.log('StudentManage: 获取学校列表完成，currentSchoolId:', this.currentSchoolId);
        
        // 确保有学校ID后再获取选项
        if (this.currentSchoolId) {
          console.log('StudentManage: 开始获取学校选项，schoolId:', this.currentSchoolId);
          await this.GET_SCHOOL_OPTIONS({
            school_id: this.currentSchoolId
          });
          console.log('StudentManage: 获取学校选项完成');
        } else {
          console.warn('StudentManage: 没有可用的学校ID，无法获取学校选项');
        }
      } catch (error) {
        console.error('StudentManage: 初始化数据失败', error);
      }
    }
  },
  created() {
    console.log('StudentManage: 组件创建');
    this.initData();
  }
}
</script>

<style lang="less" scoped>
.student-manage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  
  .student-content {
    flex: 1;
    overflow: auto;
  }
}
</style> 